package com.yserp.project.erp.order.productbom.controller;

import com.yserp.common.utils.poi.ExcelUtil;
import com.yserp.framework.aspectj.lang.annotation.Log;
import com.yserp.framework.aspectj.lang.enums.BusinessType;
import com.yserp.framework.web.controller.BaseController;
import com.yserp.framework.web.domain.AjaxResult;
import com.yserp.framework.web.page.TableDataInfo;
import com.yserp.project.erp.order.productbom.domain.ProductionBom;
import com.yserp.project.erp.order.productbom.domain.ProductionBomItem;
import com.yserp.project.erp.order.productbom.service.IProductionBomItemService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * BOM子Controller
 * 
 * @author yserp
 * @date 2022-08-09
 */
@Controller
@RequestMapping("/order/productbom/item")
public class ProductionBomItemController extends BaseController
{
    private String prefix = "erp/order/productbom";

    @Autowired
    private IProductionBomItemService productionBomItemService;

    @RequiresPermissions("order:productbom:view")
    @GetMapping()
    public String productbom()
    {
        return prefix + "/productbom";
    }

    /**
     * 查询BOM子列表
     */
    @RequiresPermissions("order:productbom:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProductionBomItem productionBomItem)
    {
        startPage();
        List<ProductionBomItem> list = productionBomItemService.selectProductionBomItemList(productionBomItem);
        return getDataTable(list);
    }

    /**
     * 导出BOM子列表
     */
    @RequiresPermissions("order:productbom:export")
    @Log(title = "BOM子", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProductionBomItem productionBomItem)
    {
        List<ProductionBomItem> list = productionBomItemService.selectProductionBomItemList(productionBomItem);
        ExcelUtil<ProductionBomItem> util = new ExcelUtil<ProductionBomItem>(ProductionBomItem.class);
        return util.exportExcel(list, "BOM子数据");
    }


    /**
     * 根据主商品ID获取BOM辅料子表列表
     */
    @PostMapping("/selectBomAidedAjaxList")
    @ResponseBody
    public AjaxResult selectBomAidedAjaxList(ProductionBom productionBom) {
        List<ProductionBomItem> mapList = productionBomItemService.selectProductionBomItemListByProductId(productionBom.getProductId());
        return AjaxResult.success(mapList);
    }

}
